/*
 * cards.c
 */

#include <time.h>
#include <stdlib.h>

#include "cards.h"

/* *********************************************************************** */
unsigned cards[] = {
    1,  2,  3,  4, 
    5,  6,  7,  8, 
    9, 10, 11, 12, 
   13, 14, 15, 16, 
   17, 18, 19, 20, 
   21, 22, 23, 24, 
   25, 26, 27, 28
};
/* locations of jokers */
unsigned loc_ja;
unsigned loc_jb;

/* *********************************************************************** */
/* Generate DECK_SIZE pairs of indicies and swap values at these locations 
 */
void
shuffle_deck(void)
{
   unsigned i = 0;
   srand((unsigned) time(NULL));
   /* shuffle all but the last two elements */
   for (;i < (DECK_SIZE - 2);)
   {
      unsigned temp, index;
      index = (rand() % (DECK_SIZE - 2));
      temp = cards[i];
      cards[i++] = cards[index];
      cards[index] = temp;
   }
   /* randomise first joker */
   i = (rand() % DECK_SIZE);
   loc_ja = i;
   cards[26] = cards[i];
   cards[i] = 27;
   /* randomise second joker */
   i = (rand() % DECK_SIZE);
   loc_jb = i;
   cards[27] = cards[i];
   cards[i] = 28;
}

/*
void
shift_jokers(void)
{
   unsigned temp, index;
   index = (loc_ja+1) % DECK_SIZE;
   cards[loc_ja]
}
*/
